package com.yanqu.road.entity.activity.rankunionwar.data;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CrossRankUnionWarMatchData {

    private int activityId;

    //唯一id，打到第几场了
    private int gameNo;

    //第几轮
    private int turn;

    //战区，青铜白银
    private int division;

    //每一个轮次的不同赛区的1开始的编号
    private int no;

    //0还没可开始打，1还在打，2打完了
    private int status;

    private String winUnionId = "";

    private long winTime;

    //队伍1
    private String unionId1;

    //队伍2
    private String unionId2;

    //士气
    private int morale1;
    private int morale2;

    //士气比拼后的胜利方
    private String attackUnionId = "";

    //玩家鼓舞次数
    private Map<Long,Integer> userInspireTimesMap = new ConcurrentHashMap<>();

    //线路 unionId 队伍列表
    private Map<Integer,CrossRankUnionWarLineData> battleLineMap = new ConcurrentHashMap<>();

    //招募和初始化时候在里面的门客，等待派遣的,或者是派遣完了还没上战场可以改的 userId patronsNo
    private Map<Long,Map<Integer,CrossRankUnionWarWaitPatronData>> waitPatronsMap = new ConcurrentHashMap<>();

    //按照时间顺序，大的前面 不用保存，缓存排序 (线路,商会)
    private Map<Integer,Map<String,List<CrossRankUnionWarWaitPatronData>>> readyPatronsSortMap = new ConcurrentHashMap<>();

    //两个队伍的支持人数，几个人就是多少
    private int union1Support;
    private int union2Support;

    private Map<Long,CrossRankUnionWarKillRankData> killRankMap = new ConcurrentHashMap<>();

    private List<CrossRankUnionWarKillRankData> killRankList = new ArrayList<>();

    private List<CrossRankUnionWarNoticeData> noticeList = new ArrayList<>();

    //围观奖励
    private List<Long> lookRewardList = new ArrayList<>();
    //比赛结束奖励
    private List<Long> matchRewardList = new ArrayList<>();

    //上次计算战斗时间,是下一次战斗的时间，就是程序下一次会计算到这个战斗时间
    private long battleTime;

    //击杀榜排序
    static class KillRankSort implements Comparator<CrossRankUnionWarKillRankData> {
        @Override
        public int compare(CrossRankUnionWarKillRankData o1, CrossRankUnionWarKillRankData o2) {
            if (o1.getKillTimes() == o2.getKillTimes() && o1.getUpdateTime() == o2.getUpdateTime()) {
                return 0;
            }
            if (o1.getKillTimes() > o2.getKillTimes() || (o1.getKillTimes() == o2.getKillTimes() && o1.getUpdateTime() >  o2.getUpdateTime())) {
                return -1;
            }
            return 1;
        }
    }

    //门客派遣排序 从小到大
    static class ReadyPatronsSort implements Comparator<CrossRankUnionWarWaitPatronData> {
        @Override
        public int compare(CrossRankUnionWarWaitPatronData o1, CrossRankUnionWarWaitPatronData o2) {
            if (o1.getLineIndex() == o2.getLineIndex()) {
                return 0;
            }
            if (o1.getLineIndex() > o2.getLineIndex()) {
                return 1;
            }
            /*if (o1.getSendTime() == o2.getSendTime() && o1.getPatronId() == o2.getPatronId()) {
                return 0;
            }
            if (o1.getSendTime() > o2.getSendTime() || (o1.getSendTime() == o2.getSendTime() && o1.getPatronId() >  o2.getPatronId())) {
                return -1;
            }*/
            return -1;
        }
    }

    public long getWinTime() {
        return winTime;
    }

    public void setWinTime(long winTime) {
        this.winTime = winTime;
    }

    public long getBattleTime() {
        return battleTime;
    }

    public void setBattleTime(long battleTime) {
        this.battleTime = battleTime;
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getTurn() {
        return turn;
    }

    public void setTurn(int turn) {
        this.turn = turn;
    }

    public int getDivision() {
        return division;
    }

    public void setDivision(int division) {
        this.division = division;
    }

    public String getUnionId1() {
        return unionId1;
    }

    public void setUnionId1(String unionId1) {
        this.unionId1 = unionId1;
    }

    public String getUnionId2() {
        return unionId2;
    }

    public void setUnionId2(String unionId2) {
        this.unionId2 = unionId2;
    }

    public int getGameNo() {
        return gameNo;
    }

    public void setGameNo(int gameNo) {
        this.gameNo = gameNo;
    }

    public Map<Integer, CrossRankUnionWarLineData> getBattleLineMap() {
        return battleLineMap;
    }

    public void setBattleLineMap(Map<Integer, CrossRankUnionWarLineData> battleLineMap) {
        this.battleLineMap = battleLineMap;
    }

    public int getUnion1Support() {
        return union1Support;
    }

    public void setUnion1Support(int union1Support) {
        this.union1Support = union1Support;
    }

    public void addUnion1Support(){
        synchronized (this){
            this.union1Support = this.union1Support + 1;
        }
    }

    public void addUnion2Support(){
        synchronized (this){
            this.union2Support = this.union2Support + 1;
        }
    }

    public int getUnion2Support() {
        return union2Support;
    }

    public void setUnion2Support(int union2Support) {
        this.union2Support = union2Support;
    }


    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getWinUnionId() {
        return winUnionId;
    }

    public void setWinUnionId(String winUnionId) {
        this.winUnionId = winUnionId;
    }

    public int getMorale1() {
        return morale1;
    }

    public void addMorale1(){
        synchronized (this){
            morale1 = morale1 + 1;
        }
    }

    public void setMorale1(int morale1) {
        this.morale1 = morale1;
    }

    public int getMorale2() {
        return morale2;
    }

    public void addMorale2(){
        synchronized (this){
            morale2 = morale2 + 1;
        }
    }

    public void setMorale2(int morale2) {
        this.morale2 = morale2;
    }

    public Map<Long, Map<Integer, CrossRankUnionWarWaitPatronData>> getWaitPatronsMap() {
        return waitPatronsMap;
    }

    public void setWaitPatronsMap(Map<Long, Map<Integer, CrossRankUnionWarWaitPatronData>> waitPatronsMap) {
        this.waitPatronsMap = waitPatronsMap;
    }

    public Map<Long, CrossRankUnionWarKillRankData> getKillRankMap() {
        return killRankMap;
    }

    public void setKillRankMap(Map<Long, CrossRankUnionWarKillRankData> killRankMap) {
        this.killRankMap = killRankMap;
        this.killRankList = new ArrayList<>(killRankMap.values());
    }

    public List<CrossRankUnionWarKillRankData> getKillRankList() {
        return killRankList;
    }

    public void setKillRankList(List<CrossRankUnionWarKillRankData> killRankList) {
        this.killRankList = killRankList;
    }

    public void sortRankList(){
        killRankList.sort(new KillRankSort());
    }

    public List<CrossRankUnionWarNoticeData> getNoticeList() {
        return noticeList;
    }

    public void setNoticeList(List<CrossRankUnionWarNoticeData> noticeList) {
        this.noticeList = noticeList;
    }


    public Map<Long, Integer> getUserInspireTimesMap() {
        return userInspireTimesMap;
    }

    public void setUserInspireTimesMap(Map<Long, Integer> userInspireTimesMap) {
        this.userInspireTimesMap = userInspireTimesMap;
    }

    public List<Long> getLookRewardList() {
        return lookRewardList;
    }

    public void setLookRewardList(List<Long> lookRewardList) {
        this.lookRewardList = lookRewardList;
    }

    public List<Long> getMatchRewardList() {
        return matchRewardList;
    }

    public void setMatchRewardList(List<Long> matchRewardList) {
        this.matchRewardList = matchRewardList;
    }

    public Map<Integer, Map<String, List<CrossRankUnionWarWaitPatronData>>> getReadyPatronsSortMap() {
        return readyPatronsSortMap;
    }

    public void setReadyPatronsSortMap(Map<Integer, Map<String, List<CrossRankUnionWarWaitPatronData>>> readyPatronsSortMap) {
        for(Map<String, List<CrossRankUnionWarWaitPatronData>> map : readyPatronsSortMap.values()){
            for(List<CrossRankUnionWarWaitPatronData> list : map.values()){
                list.sort(new ReadyPatronsSort());
                for(int index  = 1; index <= list.size();index ++ ){
                    list.get(index - 1).setLineIndex(index);
                }
            }
        }
        this.readyPatronsSortMap = readyPatronsSortMap;
    }

    public String getAttackUnionId() {
        return attackUnionId;
    }

    public void setAttackUnionId(String attackUnionId) {
        this.attackUnionId = attackUnionId;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }
}
